package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.snowgarden.*;
import com.yanqu.road.entity.activity.snowgarden.config.*;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.activity.SnowGardenProto;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.ServerLanguageMgr;

import java.util.List;
import java.util.Map;

public class SnowGardenPb {
    public static SnowGardenProto.SnowGardenUserDataMsg.Builder parseSnowGardenUserData(SnowGardenUserData data){
        SnowGardenProto.SnowGardenUserDataMsg.Builder builder = SnowGardenProto.SnowGardenUserDataMsg.newBuilder();
        builder.setPeriod(data.getPeriod());
        builder.setTimes(data.getLoopNum());
        builder.setIndex(data.getIndexNum());
        Map<Integer, SnowGardenMapData> indexDataMap = data.getIndexData();
        for(int key:indexDataMap.keySet()) {
            SnowGardenProto.SnowGardenMapDataMsg.Builder mapBuilder = SnowGardenProto.SnowGardenMapDataMsg.newBuilder();
            mapBuilder.setBuildId(indexDataMap.get(key).getBuildingID());
            mapBuilder.setLevel(indexDataMap.get(key).getLevel());
            mapBuilder.setLevel(indexDataMap.get(key).getLevel());
            mapBuilder.setIndex(key);
            builder.addIndexData(mapBuilder);
        }
        List<Integer> resultList = data.getResultList();
        builder.addAllResultList(resultList);
        builder.setSuit(data.getSuit());
        builder.setScore(data.getPeriodScore(data.getPeriod()));
        Map<Integer, SnowGardenSkinData> skinDataMap = data.getSkinList();
        for(int key:skinDataMap.keySet()) {
            SnowGardenProto.SnowGardenSkinDataMsg.Builder skinBuilder = SnowGardenProto.SnowGardenSkinDataMsg.newBuilder();
            skinBuilder.setId(key);
            skinBuilder.setLimitTime(skinDataMap.get(key).getLimitTime());
            skinBuilder.setIsUnlock(skinDataMap.get(key).isUnlock());
            builder.addSkinList(skinBuilder);
        }
        for (SnowGardenCombTriggerData d:data.getCombList()) {
            builder.addCombList(parseSnowGardenCombDataMsg(d));
        }
        builder.setIsRecharge(data.isRecharge());
        return builder;
    }

    public static SnowGardenProto.SnowGardenSyncConfigRespMsg.Builder parseSnowGardenSyncConfigRespMsg(SnowGardenConfig config, String language) {
        SnowGardenProto.SnowGardenSyncConfigRespMsg.Builder builder = SnowGardenProto.SnowGardenSyncConfigRespMsg.newBuilder();
        for (SnowGardenCombConfig value : config.getSnowGardenCombConfig().values()) {
            builder.addCombConfig(parseSnowGardenCombConfigMsg(value, language));
        }
        for (SnowGardenDollConfig value : config.getSnowGardenDollConfig().values()) {
            builder.addDollConfig(parseSnowGardenDollConfigMsg(value, language));
        }
        for (SnowGardenStatueConfig value : config.getSnowGardenStatueConfig().values()) {
            builder.addStatueConfig(parseSnowGardenStatueConfigMsg(value, language));
        }
        for (SnowGardenMapConfig value : config.getSnowGardenMapConfig().values()) {
            builder.addMapConfig(parseSnowGardenMapConfigMsg(value));
        }
        for (SnowGardenLevelConfig value : config.getSnowGardenLevelConfig().values()) {
            builder.addLevelConfig(parseSnowGardenLevelConfigMsg(value));
        }
        for (SnowGardenVisitorConfig value : config.getSnowGardenVisitorConfig().values()) {
            builder.addVisitorConfig(parseSnowGardenVisitorConfigMsg(value, language));
        }
        for (SnowGardenShowConfig value : config.getSnowGardenShowConfig().values()) {
            builder.addShowConfig(parseSnowGardenShowConfigMsg(value, language));
        }
        // 阶段参数组装下发客户端  阶段1开始#阶段1结束|阶段2开始#阶段2结束
        // 解析第一阶段
        String exchangeParam3 = "";
        long start1Second = config.getPeriod1StartTime() / 1000;
        long end1Second = config.getPeriod1EndTime() / 1000;
        exchangeParam3 = exchangeParam3.concat(start1Second + "#" + end1Second);
        exchangeParam3 = exchangeParam3.concat("|");
        long start2Second = config.getPeriod2StartTime() / 1000;
        long end2Second = config.getPeriod2EndTime() / 1000;
        exchangeParam3 = exchangeParam3.concat(start2Second + "#" + end2Second);
        builder.setActivityParam3(exchangeParam3);
        return builder;
    }

    public static SnowGardenProto.SnowGardenCombConfigMsg.Builder parseSnowGardenCombConfigMsg(SnowGardenCombConfig config, String language) {
        SnowGardenProto.SnowGardenCombConfigMsg.Builder builder = SnowGardenProto.SnowGardenCombConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setPeriod(config.getPeriod());
        builder.setComb(config.getComb());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setEffectDesc(ServerLanguageMgr.getContent(config.getEffectDesc(), language));
        builder.setParam(config.getParam());
        builder.setReward(config.getReward());
        return builder;
    }

    public static SnowGardenProto.SnowGardenDollConfigMsg.Builder parseSnowGardenDollConfigMsg(SnowGardenDollConfig config, String language) {
        SnowGardenProto.SnowGardenDollConfigMsg.Builder builder = SnowGardenProto.SnowGardenDollConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setTime(config.getTime());
        builder.setSkillName(ServerLanguageMgr.getContent(config.getSkillName(), language));
        builder.setSkillDesc(ServerLanguageMgr.getContent(config.getSkillDesc(), language));
        builder.setQuality(config.getQuality());
        builder.setPeriod(config.getPeriod());
        return builder;
    }

    public static SnowGardenProto.SnowGardenStatueConfigMsg.Builder parseSnowGardenStatueConfigMsg(SnowGardenStatueConfig config, String language) {
        SnowGardenProto.SnowGardenStatueConfigMsg.Builder builder = SnowGardenProto.SnowGardenStatueConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setScore(config.getScore());
        builder.setBackground(config.getBackGround());
        return builder;
    }

    public static SnowGardenProto.SnowGardenMapConfigMsg.Builder parseSnowGardenMapConfigMsg(SnowGardenMapConfig config){
        SnowGardenProto.SnowGardenMapConfigMsg.Builder builder = SnowGardenProto.SnowGardenMapConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setType(config.getType());
        builder.setStatueId(config.getStatueId());
        builder.setWeight(config.getWeight());
        return builder;
    }

    public static SnowGardenProto.SnowGardenLevelConfigMsg.Builder parseSnowGardenLevelConfigMsg(SnowGardenLevelConfig config){
        SnowGardenProto.SnowGardenLevelConfigMsg.Builder builder = SnowGardenProto.SnowGardenLevelConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setLevel(config.getLevel());
        builder.setGain(config.getGain());
        return builder;
    }

    public static SnowGardenProto.SnowGardenVisitorConfigMsg.Builder parseSnowGardenVisitorConfigMsg(SnowGardenVisitorConfig config, String language) {
        SnowGardenProto.SnowGardenVisitorConfigMsg.Builder builder = SnowGardenProto.SnowGardenVisitorConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setVisitorId(config.getVisitorId());
        builder.setQuality(config.getQuality());
        builder.setOccupation(config.getOccupation());
        builder.setName(MultipleLanguageMgr.getContent(config.getName(), language));//这里本地有门客和美女的名字
//        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setScore(config.getScore());
        return builder;
    }

    public static SnowGardenProto.SnowGardenShowConfigMsg.Builder parseSnowGardenShowConfigMsg(SnowGardenShowConfig config, String language) {
        SnowGardenProto.SnowGardenShowConfigMsg.Builder builder = SnowGardenProto.SnowGardenShowConfigMsg.newBuilder();
        builder.setQuality(config.getQuality());
        builder.setRoleId(config.getRoleId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setWeight(config.getWeight());
        return builder;
    }

    public static SnowGardenProto.SnowGardenCombDataMsg.Builder parseSnowGardenCombDataMsg(SnowGardenCombTriggerData data) {
        SnowGardenProto.SnowGardenCombDataMsg.Builder builder = SnowGardenProto.SnowGardenCombDataMsg.newBuilder();
        builder.setId(data.getCombId());
        builder.setParam(data.getParam());
        builder.setSkipParam(data.getSkipParam());
        return builder;
    }

    public static SnowGardenProto.SnowGardenVisitUserDataMsg.Builder parseSnowGardenVisitUserData(SnowGardenVisitUserData data){
        SnowGardenProto.SnowGardenVisitUserDataMsg.Builder builder = SnowGardenProto.SnowGardenVisitUserDataMsg.newBuilder();
        builder.setUserId(data.getUserId());
        builder.setUserData(PlayerBasePb.parsePlayerBaseTempMsg(data.getUserData()));
        builder.setScore(data.getScore());
        builder.setBuildingLevel(data.getBuildingLevel());
        builder.setHelpTimes(data.getHelpTimes());
        return builder;
    }

    public static SnowGardenProto.SnowGardenVisitRecordDataMsg.Builder parseSnowGardenVisitUserData(SnowGardenVisitorRecord data, UserBaseInfo baseInfo) {
        SnowGardenProto.SnowGardenVisitRecordDataMsg.Builder builder = SnowGardenProto.SnowGardenVisitRecordDataMsg.newBuilder();
        builder.setUserId(data.getUserId());
        builder.setUserData(PlayerBasePb.parsePlayerBaseTempMsg(baseInfo));
        builder.setType(data.getType());
        builder.setId(data.getId());
        builder.setScore(data.getScore());
        builder.setTime(data.getTime());
        return builder;
    }

    public static SnowGardenProto.VisitOtherSnowGardenTemp.Builder parseVisitOtherSnowGardenTemp(SnowGardenUserData userData) {
        SnowGardenProto.VisitOtherSnowGardenTemp.Builder builder = SnowGardenProto.VisitOtherSnowGardenTemp.newBuilder();
        builder.setUserId(userData.getUserId());
        builder.setSuit(userData.getSuit());
        builder.setScore(userData.getPeriodScore(userData.getPeriod()));
        builder.setPeriod(userData.getPeriod());
        Map<Integer, SnowGardenMapData> indexDataMap = userData.getIndexData();
        for (int key : indexDataMap.keySet()) {
            SnowGardenProto.SnowGardenMapDataMsg.Builder mapBuilder = SnowGardenProto.SnowGardenMapDataMsg.newBuilder();
            mapBuilder.setBuildId(indexDataMap.get(key).getBuildingID());
            mapBuilder.setLevel(indexDataMap.get(key).getLevel());
            mapBuilder.setLevel(indexDataMap.get(key).getLevel());
            mapBuilder.setIndex(key);
            builder.addIndexData(mapBuilder);
        }
        return builder;
    }
}
